package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import pojo.Employee;
import util.DButil;

public class EmDao {
	static ResultSet rs=null;
	public static List<Employee> FindAll() {
		Employee emp=null;
		List<Employee> list = new ArrayList<Employee>();
		String sql = "select * from employee";
		try {
			rs = DButil.executeRs(sql, null);
			while (rs.next()) {
				emp = new Employee();
				int id=rs.getInt("id");
				emp.setId(id);
				String name = rs.getString("name");
				emp.setName(name);
				String sex = rs.getString("sex");
				emp.setSex(sex);
				int age = rs.getInt("age");
				emp.setAge(age);
				String dapartment = rs.getString("dapartment");
				emp.setDapartment(dapartment);
				String type = rs.getString("type");
				emp.setType(type);
				int year = rs.getInt("year");
				emp.setYear(year);
				list.add(emp);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			DButil.closeAll(rs, DButil.connect, DButil.pstmt);
		}
		return list;
	}
public static Employee FindOneById(int id) {
	for (Employee emp : FindAll()) {
		if(emp.getId()==id)
			return emp;
	}
	return null;
}
}
